{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "powered-taylor",
   "metadata": {},
   "source": [
    "# 导入数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "electric-broad",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "from sklearn.datasets import load_iris\n",
    "from sklearn.model_selection import train_test_split, GridSearchCV, cross_val_score\n",
    "from sklearn.linear_model import LogisticRegression as LR\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "from sklearn import metrics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "pressing-sailing",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[5.1, 3.5, 1.4, 0.2],\n",
       "       [4.9, 3. , 1.4, 0.2],\n",
       "       [4.7, 3.2, 1.3, 0.2],\n",
       "       [4.6, 3.1, 1.5, 0.2],\n",
       "       [5. , 3.6, 1.4, 0.2],\n",
       "       [5.4, 3.9, 1.7, 0.4],\n",
       "       [4.6, 3.4, 1.4, 0.3],\n",
       "       [5. , 3.4, 1.5, 0.2],\n",
       "       [4.4, 2.9, 1.4, 0.2],\n",
       "       [4.9, 3.1, 1.5, 0.1],\n",
       "       [5.4, 3.7, 1.5, 0.2],\n",
       "       [4.8, 3.4, 1.6, 0.2],\n",
       "       [4.8, 3. , 1.4, 0.1],\n",
       "       [4.3, 3. , 1.1, 0.1],\n",
       "       [5.8, 4. , 1.2, 0.2],\n",
       "       [5.7, 4.4, 1.5, 0.4],\n",
       "       [5.4, 3.9, 1.3, 0.4],\n",
       "       [5.1, 3.5, 1.4, 0.3],\n",
       "       [5.7, 3.8, 1.7, 0.3],\n",
       "       [5.1, 3.8, 1.5, 0.3],\n",
       "       [5.4, 3.4, 1.7, 0.2],\n",
       "       [5.1, 3.7, 1.5, 0.4],\n",
       "       [4.6, 3.6, 1. , 0.2],\n",
       "       [5.1, 3.3, 1.7, 0.5],\n",
       "       [4.8, 3.4, 1.9, 0.2],\n",
       "       [5. , 3. , 1.6, 0.2],\n",
       "       [5. , 3.4, 1.6, 0.4],\n",
       "       [5.2, 3.5, 1.5, 0.2],\n",
       "       [5.2, 3.4, 1.4, 0.2],\n",
       "       [4.7, 3.2, 1.6, 0.2],\n",
       "       [4.8, 3.1, 1.6, 0.2],\n",
       "       [5.4, 3.4, 1.5, 0.4],\n",
       "       [5.2, 4.1, 1.5, 0.1],\n",
       "       [5.5, 4.2, 1.4, 0.2],\n",
       "       [4.9, 3.1, 1.5, 0.2],\n",
       "       [5. , 3.2, 1.2, 0.2],\n",
       "       [5.5, 3.5, 1.3, 0.2],\n",
       "       [4.9, 3.6, 1.4, 0.1],\n",
       "       [4.4, 3. , 1.3, 0.2],\n",
       "       [5.1, 3.4, 1.5, 0.2],\n",
       "       [5. , 3.5, 1.3, 0.3],\n",
       "       [4.5, 2.3, 1.3, 0.3],\n",
       "       [4.4, 3.2, 1.3, 0.2],\n",
       "       [5. , 3.5, 1.6, 0.6],\n",
       "       [5.1, 3.8, 1.9, 0.4],\n",
       "       [4.8, 3. , 1.4, 0.3],\n",
       "       [5.1, 3.8, 1.6, 0.2],\n",
       "       [4.6, 3.2, 1.4, 0.2],\n",
       "       [5.3, 3.7, 1.5, 0.2],\n",
       "       [5. , 3.3, 1.4, 0.2],\n",
       "       [7. , 3.2, 4.7, 1.4],\n",
       "       [6.4, 3.2, 4.5, 1.5],\n",
       "       [6.9, 3.1, 4.9, 1.5],\n",
       "       [5.5, 2.3, 4. , 1.3],\n",
       "       [6.5, 2.8, 4.6, 1.5],\n",
       "       [5.7, 2.8, 4.5, 1.3],\n",
       "       [6.3, 3.3, 4.7, 1.6],\n",
       "       [4.9, 2.4, 3.3, 1. ],\n",
       "       [6.6, 2.9, 4.6, 1.3],\n",
       "       [5.2, 2.7, 3.9, 1.4],\n",
       "       [5. , 2. , 3.5, 1. ],\n",
       "       [5.9, 3. , 4.2, 1.5],\n",
       "       [6. , 2.2, 4. , 1. ],\n",
       "       [6.1, 2.9, 4.7, 1.4],\n",
       "       [5.6, 2.9, 3.6, 1.3],\n",
       "       [6.7, 3.1, 4.4, 1.4],\n",
       "       [5.6, 3. , 4.5, 1.5],\n",
       "       [5.8, 2.7, 4.1, 1. ],\n",
       "       [6.2, 2.2, 4.5, 1.5],\n",
       "       [5.6, 2.5, 3.9, 1.1],\n",
       "       [5.9, 3.2, 4.8, 1.8],\n",
       "       [6.1, 2.8, 4. , 1.3],\n",
       "       [6.3, 2.5, 4.9, 1.5],\n",
       "       [6.1, 2.8, 4.7, 1.2],\n",
       "       [6.4, 2.9, 4.3, 1.3],\n",
       "       [6.6, 3. , 4.4, 1.4],\n",
       "       [6.8, 2.8, 4.8, 1.4],\n",
       "       [6.7, 3. , 5. , 1.7],\n",
       "       [6. , 2.9, 4.5, 1.5],\n",
       "       [5.7, 2.6, 3.5, 1. ],\n",
       "       [5.5, 2.4, 3.8, 1.1],\n",
       "       [5.5, 2.4, 3.7, 1. ],\n",
       "       [5.8, 2.7, 3.9, 1.2],\n",
       "       [6. , 2.7, 5.1, 1.6],\n",
       "       [5.4, 3. , 4.5, 1.5],\n",
       "       [6. , 3.4, 4.5, 1.6],\n",
       "       [6.7, 3.1, 4.7, 1.5],\n",
       "       [6.3, 2.3, 4.4, 1.3],\n",
       "       [5.6, 3. , 4.1, 1.3],\n",
       "       [5.5, 2.5, 4. , 1.3],\n",
       "       [5.5, 2.6, 4.4, 1.2],\n",
       "       [6.1, 3. , 4.6, 1.4],\n",
       "       [5.8, 2.6, 4. , 1.2],\n",
       "       [5. , 2.3, 3.3, 1. ],\n",
       "       [5.6, 2.7, 4.2, 1.3],\n",
       "       [5.7, 3. , 4.2, 1.2],\n",
       "       [5.7, 2.9, 4.2, 1.3],\n",
       "       [6.2, 2.9, 4.3, 1.3],\n",
       "       [5.1, 2.5, 3. , 1.1],\n",
       "       [5.7, 2.8, 4.1, 1.3],\n",
       "       [6.3, 3.3, 6. , 2.5],\n",
       "       [5.8, 2.7, 5.1, 1.9],\n",
       "       [7.1, 3. , 5.9, 2.1],\n",
       "       [6.3, 2.9, 5.6, 1.8],\n",
       "       [6.5, 3. , 5.8, 2.2],\n",
       "       [7.6, 3. , 6.6, 2.1],\n",
       "       [4.9, 2.5, 4.5, 1.7],\n",
       "       [7.3, 2.9, 6.3, 1.8],\n",
       "       [6.7, 2.5, 5.8, 1.8],\n",
       "       [7.2, 3.6, 6.1, 2.5],\n",
       "       [6.5, 3.2, 5.1, 2. ],\n",
       "       [6.4, 2.7, 5.3, 1.9],\n",
       "       [6.8, 3. , 5.5, 2.1],\n",
       "       [5.7, 2.5, 5. , 2. ],\n",
       "       [5.8, 2.8, 5.1, 2.4],\n",
       "       [6.4, 3.2, 5.3, 2.3],\n",
       "       [6.5, 3. , 5.5, 1.8],\n",
       "       [7.7, 3.8, 6.7, 2.2],\n",
       "       [7.7, 2.6, 6.9, 2.3],\n",
       "       [6. , 2.2, 5. , 1.5],\n",
       "       [6.9, 3.2, 5.7, 2.3],\n",
       "       [5.6, 2.8, 4.9, 2. ],\n",
       "       [7.7, 2.8, 6.7, 2. ],\n",
       "       [6.3, 2.7, 4.9, 1.8],\n",
       "       [6.7, 3.3, 5.7, 2.1],\n",
       "       [7.2, 3.2, 6. , 1.8],\n",
       "       [6.2, 2.8, 4.8, 1.8],\n",
       "       [6.1, 3. , 4.9, 1.8],\n",
       "       [6.4, 2.8, 5.6, 2.1],\n",
       "       [7.2, 3. , 5.8, 1.6],\n",
       "       [7.4, 2.8, 6.1, 1.9],\n",
       "       [7.9, 3.8, 6.4, 2. ],\n",
       "       [6.4, 2.8, 5.6, 2.2],\n",
       "       [6.3, 2.8, 5.1, 1.5],\n",
       "       [6.1, 2.6, 5.6, 1.4],\n",
       "       [7.7, 3. , 6.1, 2.3],\n",
       "       [6.3, 3.4, 5.6, 2.4],\n",
       "       [6.4, 3.1, 5.5, 1.8],\n",
       "       [6. , 3. , 4.8, 1.8],\n",
       "       [6.9, 3.1, 5.4, 2.1],\n",
       "       [6.7, 3.1, 5.6, 2.4],\n",
       "       [6.9, 3.1, 5.1, 2.3],\n",
       "       [5.8, 2.7, 5.1, 1.9],\n",
       "       [6.8, 3.2, 5.9, 2.3],\n",
       "       [6.7, 3.3, 5.7, 2.5],\n",
       "       [6.7, 3. , 5.2, 2.3],\n",
       "       [6.3, 2.5, 5. , 1.9],\n",
       "       [6.5, 3. , 5.2, 2. ],\n",
       "       [6.2, 3.4, 5.4, 2.3],\n",
       "       [5.9, 3. , 5.1, 1.8]])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X = load_iris().data\n",
    "X"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "corporate-silly",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
       "       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
       "       0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n",
       "       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n",
       "       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Y = load_iris().target\n",
    "Y"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "educated-casino",
   "metadata": {},
   "source": [
    "# 切分数据集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "progressive-carnival",
   "metadata": {},
   "outputs": [],
   "source": [
    "Xtrain,Xtest,Ytrain,Ytest = train_test_split(X,Y,test_size=0.3,random_state=420)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "crazy-radical",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[6.5, 3.2, 5.1, 2. ],\n",
       "       [6.3, 2.3, 4.4, 1.3],\n",
       "       [4.9, 3.1, 1.5, 0.2],\n",
       "       [7.2, 3.2, 6. , 1.8],\n",
       "       [4.9, 3. , 1.4, 0.2],\n",
       "       [6.2, 3.4, 5.4, 2.3],\n",
       "       [5.5, 3.5, 1.3, 0.2],\n",
       "       [5.1, 3.8, 1.5, 0.3],\n",
       "       [5.8, 2.8, 5.1, 2.4],\n",
       "       [6.1, 3. , 4.9, 1.8],\n",
       "       [5.2, 4.1, 1.5, 0.1],\n",
       "       [7.9, 3.8, 6.4, 2. ],\n",
       "       [7. , 3.2, 4.7, 1.4],\n",
       "       [6.8, 3.2, 5.9, 2.3],\n",
       "       [5.6, 2.5, 3.9, 1.1],\n",
       "       [6.1, 2.8, 4. , 1.3],\n",
       "       [6.7, 3.3, 5.7, 2.5],\n",
       "       [4.8, 3. , 1.4, 0.3],\n",
       "       [4.8, 3.4, 1.9, 0.2],\n",
       "       [5.7, 2.5, 5. , 2. ],\n",
       "       [7.7, 2.8, 6.7, 2. ],\n",
       "       [6.9, 3.1, 5.1, 2.3],\n",
       "       [7.1, 3. , 5.9, 2.1],\n",
       "       [5.1, 3.5, 1.4, 0.2],\n",
       "       [4.3, 3. , 1.1, 0.1],\n",
       "       [5.7, 3.8, 1.7, 0.3],\n",
       "       [5.1, 3.7, 1.5, 0.4],\n",
       "       [6. , 2.2, 5. , 1.5],\n",
       "       [5. , 3.6, 1.4, 0.2],\n",
       "       [4.4, 3. , 1.3, 0.2],\n",
       "       [7.7, 3. , 6.1, 2.3],\n",
       "       [4.8, 3.1, 1.6, 0.2],\n",
       "       [5.3, 3.7, 1.5, 0.2],\n",
       "       [6. , 2.2, 4. , 1. ],\n",
       "       [5.6, 2.7, 4.2, 1.3],\n",
       "       [4.5, 2.3, 1.3, 0.3],\n",
       "       [7.2, 3.6, 6.1, 2.5],\n",
       "       [6.4, 2.9, 4.3, 1.3],\n",
       "       [5.7, 2.6, 3.5, 1. ],\n",
       "       [7.7, 3.8, 6.7, 2.2],\n",
       "       [4.9, 2.5, 4.5, 1.7],\n",
       "       [5. , 3.5, 1.6, 0.6],\n",
       "       [5.9, 3. , 4.2, 1.5],\n",
       "       [5. , 3.5, 1.3, 0.3],\n",
       "       [4.6, 3.1, 1.5, 0.2],\n",
       "       [6.7, 3.1, 5.6, 2.4],\n",
       "       [5.1, 3.8, 1.9, 0.4],\n",
       "       [5.7, 4.4, 1.5, 0.4],\n",
       "       [5.4, 3.9, 1.3, 0.4],\n",
       "       [5. , 3.4, 1.6, 0.4],\n",
       "       [6.7, 3.1, 4.4, 1.4],\n",
       "       [6. , 2.9, 4.5, 1.5],\n",
       "       [4.7, 3.2, 1.6, 0.2],\n",
       "       [6.7, 2.5, 5.8, 1.8],\n",
       "       [5.7, 2.8, 4.1, 1.3],\n",
       "       [5.8, 2.7, 5.1, 1.9],\n",
       "       [6.3, 3.3, 6. , 2.5],\n",
       "       [5.8, 2.6, 4. , 1.2],\n",
       "       [7.2, 3. , 5.8, 1.6],\n",
       "       [6.7, 3.1, 4.7, 1.5],\n",
       "       [5.1, 2.5, 3. , 1.1],\n",
       "       [5. , 2. , 3.5, 1. ],\n",
       "       [6.9, 3.2, 5.7, 2.3],\n",
       "       [5.8, 4. , 1.2, 0.2],\n",
       "       [6.2, 2.2, 4.5, 1.5],\n",
       "       [5.7, 2.9, 4.2, 1.3],\n",
       "       [7.7, 2.6, 6.9, 2.3],\n",
       "       [6.3, 2.9, 5.6, 1.8],\n",
       "       [6.3, 2.8, 5.1, 1.5],\n",
       "       [6.1, 2.8, 4.7, 1.2],\n",
       "       [5.6, 3. , 4.1, 1.3],\n",
       "       [6.4, 2.8, 5.6, 2.1],\n",
       "       [6.6, 3. , 4.4, 1.4],\n",
       "       [4.9, 3.1, 1.5, 0.1],\n",
       "       [4.4, 2.9, 1.4, 0.2],\n",
       "       [6.4, 3.1, 5.5, 1.8],\n",
       "       [6.4, 2.7, 5.3, 1.9],\n",
       "       [5.1, 3.3, 1.7, 0.5],\n",
       "       [5.2, 3.4, 1.4, 0.2],\n",
       "       [4.9, 2.4, 3.3, 1. ],\n",
       "       [6.7, 3. , 5. , 1.7],\n",
       "       [6.5, 3. , 5.2, 2. ],\n",
       "       [5.8, 2.7, 5.1, 1.9],\n",
       "       [6.9, 3.1, 4.9, 1.5],\n",
       "       [5.4, 3.9, 1.7, 0.4],\n",
       "       [5.2, 2.7, 3.9, 1.4],\n",
       "       [5.6, 2.8, 4.9, 2. ],\n",
       "       [7.4, 2.8, 6.1, 1.9],\n",
       "       [5.7, 3. , 4.2, 1.2],\n",
       "       [7.3, 2.9, 6.3, 1.8],\n",
       "       [6.3, 2.5, 5. , 1.9],\n",
       "       [6.8, 2.8, 4.8, 1.4],\n",
       "       [4.6, 3.2, 1.4, 0.2],\n",
       "       [4.9, 3.6, 1.4, 0.1],\n",
       "       [6. , 3.4, 4.5, 1.6],\n",
       "       [6.4, 2.8, 5.6, 2.2],\n",
       "       [5. , 3.2, 1.2, 0.2],\n",
       "       [6.2, 2.8, 4.8, 1.8],\n",
       "       [5.9, 3. , 5.1, 1.8],\n",
       "       [5.4, 3.7, 1.5, 0.2],\n",
       "       [6.4, 3.2, 5.3, 2.3],\n",
       "       [5.4, 3.4, 1.5, 0.4],\n",
       "       [6.1, 2.9, 4.7, 1.4],\n",
       "       [6.1, 2.6, 5.6, 1.4],\n",
       "       [6.3, 2.5, 4.9, 1.5]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Xtrain"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "constitutional-debate",
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[5.6, 3. , 4.5, 1.5],\n",
       "       [6.5, 3. , 5.8, 2.2],\n",
       "       [7.6, 3. , 6.6, 2.1],\n",
       "       [4.7, 3.2, 1.3, 0.2],\n",
       "       [5. , 3.4, 1.5, 0.2],\n",
       "       [5.8, 2.7, 4.1, 1. ],\n",
       "       [5.2, 3.5, 1.5, 0.2],\n",
       "       [5.5, 2.6, 4.4, 1.2],\n",
       "       [6. , 3. , 4.8, 1.8],\n",
       "       [6.1, 3. , 4.6, 1.4],\n",
       "       [6.9, 3.1, 5.4, 2.1],\n",
       "       [5.4, 3. , 4.5, 1.5],\n",
       "       [4.6, 3.6, 1. , 0.2],\n",
       "       [5. , 3. , 1.6, 0.2],\n",
       "       [6.8, 3. , 5.5, 2.1],\n",
       "       [5.8, 2.7, 3.9, 1.2],\n",
       "       [4.4, 3.2, 1.3, 0.2],\n",
       "       [4.6, 3.4, 1.4, 0.3],\n",
       "       [4.8, 3.4, 1.6, 0.2],\n",
       "       [5.1, 3.8, 1.6, 0.2],\n",
       "       [5.4, 3.4, 1.7, 0.2],\n",
       "       [6.7, 3. , 5.2, 2.3],\n",
       "       [5.5, 2.5, 4. , 1.3],\n",
       "       [4.8, 3. , 1.4, 0.1],\n",
       "       [6.5, 2.8, 4.6, 1.5],\n",
       "       [6.3, 3.3, 4.7, 1.6],\n",
       "       [5.1, 3.4, 1.5, 0.2],\n",
       "       [5.5, 4.2, 1.4, 0.2],\n",
       "       [5.5, 2.4, 3.7, 1. ],\n",
       "       [6.6, 2.9, 4.6, 1.3],\n",
       "       [5. , 2.3, 3.3, 1. ],\n",
       "       [6.3, 2.7, 4.9, 1.8],\n",
       "       [6.7, 3.3, 5.7, 2.1],\n",
       "       [5. , 3.3, 1.4, 0.2],\n",
       "       [5.1, 3.5, 1.4, 0.3],\n",
       "       [6.4, 3.2, 4.5, 1.5],\n",
       "       [6.3, 3.4, 5.6, 2.4],\n",
       "       [5.6, 2.9, 3.6, 1.3],\n",
       "       [5.9, 3.2, 4.8, 1.8],\n",
       "       [5.7, 2.8, 4.5, 1.3],\n",
       "       [5.5, 2.4, 3.8, 1.1],\n",
       "       [6.2, 2.9, 4.3, 1.3],\n",
       "       [5.5, 2.3, 4. , 1.3],\n",
       "       [6. , 2.7, 5.1, 1.6],\n",
       "       [6.5, 3. , 5.5, 1.8]])"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Xtest"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "numeric-european",
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 6.98926548e-01,  3.11391996e-01,  7.07721645e-01,\n",
       "         9.95825472e-01],\n",
       "       [ 4.65951032e-01, -1.67688798e+00,  3.19241130e-01,\n",
       "         8.77215987e-02],\n",
       "       [-1.16487758e+00,  9.04719988e-02, -1.29017814e+00,\n",
       "        -1.33929877e+00],\n",
       "       [ 1.51434085e+00,  3.11391996e-01,  1.20719659e+00,\n",
       "         7.36367223e-01],\n",
       "       [-1.16487758e+00, -1.30447998e-01, -1.34567536e+00,\n",
       "        -1.33929877e+00],\n",
       "       [ 3.49463274e-01,  7.53231990e-01,  8.74213294e-01,\n",
       "         1.38501285e+00],\n",
       "       [-4.65951032e-01,  9.74151987e-01, -1.40117258e+00,\n",
       "        -1.33929877e+00],\n",
       "       [-9.31902064e-01,  1.63691198e+00, -1.29017814e+00,\n",
       "        -1.20956965e+00],\n",
       "       [-1.16487758e-01, -5.72287992e-01,  7.07721645e-01,\n",
       "         1.51474197e+00],\n",
       "       [ 2.32975516e-01, -1.30447998e-01,  5.96727212e-01,\n",
       "         7.36367223e-01],\n",
       "       [-8.15414306e-01,  2.29967197e+00, -1.29017814e+00,\n",
       "        -1.46902790e+00],\n",
       "       [ 2.32975516e+00,  1.63691198e+00,  1.42918546e+00,\n",
       "         9.95825472e-01],\n",
       "       [ 1.28136534e+00,  3.11391996e-01,  4.85732779e-01,\n",
       "         2.17450723e-01],\n",
       "       [ 1.04838982e+00,  3.11391996e-01,  1.15169938e+00,\n",
       "         1.38501285e+00],\n",
       "       [-3.49463274e-01, -1.23504798e+00,  4.17550485e-02,\n",
       "        -1.71736651e-01],\n",
       "       [ 2.32975516e-01, -5.72287992e-01,  9.72522648e-02,\n",
       "         8.77215987e-02],\n",
       "       [ 9.31902064e-01,  5.32311993e-01,  1.04070494e+00,\n",
       "         1.64447110e+00],\n",
       "       [-1.28136534e+00, -1.30447998e-01, -1.34567536e+00,\n",
       "        -1.20956965e+00],\n",
       "       [-1.28136534e+00,  7.53231990e-01, -1.06818928e+00,\n",
       "        -1.33929877e+00],\n",
       "       [-2.32975516e-01, -1.23504798e+00,  6.52224428e-01,\n",
       "         9.95825472e-01],\n",
       "       [ 2.09677965e+00, -5.72287992e-01,  1.59567711e+00,\n",
       "         9.95825472e-01],\n",
       "       [ 1.16487758e+00,  9.04719988e-02,  7.07721645e-01,\n",
       "         1.38501285e+00],\n",
       "       [ 1.39785310e+00, -1.30447998e-01,  1.15169938e+00,\n",
       "         1.12555460e+00],\n",
       "       [-9.31902064e-01,  9.74151987e-01, -1.34567536e+00,\n",
       "        -1.33929877e+00],\n",
       "       [-1.86380413e+00, -1.30447998e-01, -1.51216701e+00,\n",
       "        -1.46902790e+00],\n",
       "       [-2.32975516e-01,  1.63691198e+00, -1.17918371e+00,\n",
       "        -1.20956965e+00],\n",
       "       [-9.31902064e-01,  1.41599198e+00, -1.29017814e+00,\n",
       "        -1.07984052e+00],\n",
       "       [ 1.16487758e-01, -1.89780797e+00,  6.52224428e-01,\n",
       "         3.47179848e-01],\n",
       "       [-1.04838982e+00,  1.19507198e+00, -1.34567536e+00,\n",
       "        -1.33929877e+00],\n",
       "       [-1.74731637e+00, -1.30447998e-01, -1.40117258e+00,\n",
       "        -1.33929877e+00],\n",
       "       [ 2.09677965e+00, -1.30447998e-01,  1.26269381e+00,\n",
       "         1.38501285e+00],\n",
       "       [-1.28136534e+00,  9.04719988e-02, -1.23468093e+00,\n",
       "        -1.33929877e+00],\n",
       "       [-6.98926548e-01,  1.41599198e+00, -1.29017814e+00,\n",
       "        -1.33929877e+00],\n",
       "       [ 1.16487758e-01, -1.89780797e+00,  9.72522648e-02,\n",
       "        -3.01465776e-01],\n",
       "       [-3.49463274e-01, -7.93207989e-01,  2.08246698e-01,\n",
       "         8.77215987e-02],\n",
       "       [-1.63082861e+00, -1.67688798e+00, -1.40117258e+00,\n",
       "        -1.20956965e+00],\n",
       "       [ 1.51434085e+00,  1.19507198e+00,  1.26269381e+00,\n",
       "         1.64447110e+00],\n",
       "       [ 5.82438790e-01, -3.51367995e-01,  2.63743914e-01,\n",
       "         8.77215987e-02],\n",
       "       [-2.32975516e-01, -1.01412799e+00, -1.80233817e-01,\n",
       "        -3.01465776e-01],\n",
       "       [ 2.09677965e+00,  1.63691198e+00,  1.59567711e+00,\n",
       "         1.25528372e+00],\n",
       "       [-1.16487758e+00, -1.23504798e+00,  3.74738347e-01,\n",
       "         6.06638098e-01],\n",
       "       [-1.04838982e+00,  9.74151987e-01, -1.23468093e+00,\n",
       "        -8.20382275e-01],\n",
       "       [ 4.13847651e-15, -1.30447998e-01,  2.08246698e-01,\n",
       "         3.47179848e-01],\n",
       "       [-1.04838982e+00,  9.74151987e-01, -1.40117258e+00,\n",
       "        -1.20956965e+00],\n",
       "       [-1.51434085e+00,  9.04719988e-02, -1.29017814e+00,\n",
       "        -1.33929877e+00],\n",
       "       [ 9.31902064e-01,  9.04719988e-02,  9.85207726e-01,\n",
       "         1.51474197e+00],\n",
       "       [-9.31902064e-01,  1.63691198e+00, -1.06818928e+00,\n",
       "        -1.07984052e+00],\n",
       "       [-2.32975516e-01,  2.96243196e+00, -1.29017814e+00,\n",
       "        -1.07984052e+00],\n",
       "       [-5.82438790e-01,  1.85783197e+00, -1.40117258e+00,\n",
       "        -1.07984052e+00],\n",
       "       [-1.04838982e+00,  7.53231990e-01, -1.23468093e+00,\n",
       "        -1.07984052e+00],\n",
       "       [ 9.31902064e-01,  9.04719988e-02,  3.19241130e-01,\n",
       "         2.17450723e-01],\n",
       "       [ 1.16487758e-01, -3.51367995e-01,  3.74738347e-01,\n",
       "         3.47179848e-01],\n",
       "       [-1.39785310e+00,  3.11391996e-01, -1.23468093e+00,\n",
       "        -1.33929877e+00],\n",
       "       [ 9.31902064e-01, -1.23504798e+00,  1.09620216e+00,\n",
       "         7.36367223e-01],\n",
       "       [-2.32975516e-01, -5.72287992e-01,  1.52749481e-01,\n",
       "         8.77215987e-02],\n",
       "       [-1.16487758e-01, -7.93207989e-01,  7.07721645e-01,\n",
       "         8.66096347e-01],\n",
       "       [ 4.65951032e-01,  5.32311993e-01,  1.20719659e+00,\n",
       "         1.64447110e+00],\n",
       "       [-1.16487758e-01, -1.01412799e+00,  9.72522648e-02,\n",
       "        -4.20075261e-02],\n",
       "       [ 1.51434085e+00, -1.30447998e-01,  1.09620216e+00,\n",
       "         4.76908973e-01],\n",
       "       [ 9.31902064e-01,  9.04719988e-02,  4.85732779e-01,\n",
       "         3.47179848e-01],\n",
       "       [-9.31902064e-01, -1.23504798e+00, -4.57719899e-01,\n",
       "        -1.71736651e-01],\n",
       "       [-1.04838982e+00, -2.33964797e+00, -1.80233817e-01,\n",
       "        -3.01465776e-01],\n",
       "       [ 1.16487758e+00,  3.11391996e-01,  1.04070494e+00,\n",
       "         1.38501285e+00],\n",
       "       [-1.16487758e-01,  2.07875197e+00, -1.45666979e+00,\n",
       "        -1.33929877e+00],\n",
       "       [ 3.49463274e-01, -1.89780797e+00,  3.74738347e-01,\n",
       "         3.47179848e-01],\n",
       "       [-2.32975516e-01, -3.51367995e-01,  2.08246698e-01,\n",
       "         8.77215987e-02],\n",
       "       [ 2.09677965e+00, -1.01412799e+00,  1.70667154e+00,\n",
       "         1.38501285e+00],\n",
       "       [ 4.65951032e-01, -3.51367995e-01,  9.85207726e-01,\n",
       "         7.36367223e-01],\n",
       "       [ 4.65951032e-01, -5.72287992e-01,  7.07721645e-01,\n",
       "         3.47179848e-01],\n",
       "       [ 2.32975516e-01, -5.72287992e-01,  4.85732779e-01,\n",
       "        -4.20075261e-02],\n",
       "       [-3.49463274e-01, -1.30447998e-01,  1.52749481e-01,\n",
       "         8.77215987e-02],\n",
       "       [ 5.82438790e-01, -5.72287992e-01,  9.85207726e-01,\n",
       "         1.12555460e+00],\n",
       "       [ 8.15414306e-01, -1.30447998e-01,  3.19241130e-01,\n",
       "         2.17450723e-01],\n",
       "       [-1.16487758e+00,  9.04719988e-02, -1.29017814e+00,\n",
       "        -1.46902790e+00],\n",
       "       [-1.74731637e+00, -3.51367995e-01, -1.34567536e+00,\n",
       "        -1.33929877e+00],\n",
       "       [ 5.82438790e-01,  9.04719988e-02,  9.29710510e-01,\n",
       "         7.36367223e-01],\n",
       "       [ 5.82438790e-01, -7.93207989e-01,  8.18716077e-01,\n",
       "         8.66096347e-01],\n",
       "       [-9.31902064e-01,  5.32311993e-01, -1.17918371e+00,\n",
       "        -9.50111400e-01],\n",
       "       [-8.15414306e-01,  7.53231990e-01, -1.34567536e+00,\n",
       "        -1.33929877e+00],\n",
       "       [-1.16487758e+00, -1.45596798e+00, -2.91228250e-01,\n",
       "        -3.01465776e-01],\n",
       "       [ 9.31902064e-01, -1.30447998e-01,  6.52224428e-01,\n",
       "         6.06638098e-01],\n",
       "       [ 6.98926548e-01, -1.30447998e-01,  7.63218861e-01,\n",
       "         9.95825472e-01],\n",
       "       [-1.16487758e-01, -7.93207989e-01,  7.07721645e-01,\n",
       "         8.66096347e-01],\n",
       "       [ 1.16487758e+00,  9.04719988e-02,  5.96727212e-01,\n",
       "         3.47179848e-01],\n",
       "       [-5.82438790e-01,  1.85783197e+00, -1.17918371e+00,\n",
       "        -1.07984052e+00],\n",
       "       [-8.15414306e-01, -7.93207989e-01,  4.17550485e-02,\n",
       "         2.17450723e-01],\n",
       "       [-3.49463274e-01, -5.72287992e-01,  5.96727212e-01,\n",
       "         9.95825472e-01],\n",
       "       [ 1.74731637e+00, -5.72287992e-01,  1.26269381e+00,\n",
       "         8.66096347e-01],\n",
       "       [-2.32975516e-01, -1.30447998e-01,  2.08246698e-01,\n",
       "        -4.20075261e-02],\n",
       "       [ 1.63082861e+00, -3.51367995e-01,  1.37368824e+00,\n",
       "         7.36367223e-01],\n",
       "       [ 4.65951032e-01, -1.23504798e+00,  6.52224428e-01,\n",
       "         8.66096347e-01],\n",
       "       [ 1.04838982e+00, -5.72287992e-01,  5.41229996e-01,\n",
       "         2.17450723e-01],\n",
       "       [-1.51434085e+00,  3.11391996e-01, -1.34567536e+00,\n",
       "        -1.33929877e+00],\n",
       "       [-1.16487758e+00,  1.19507198e+00, -1.34567536e+00,\n",
       "        -1.46902790e+00],\n",
       "       [ 1.16487758e-01,  7.53231990e-01,  3.74738347e-01,\n",
       "         4.76908973e-01],\n",
       "       [ 5.82438790e-01, -5.72287992e-01,  9.85207726e-01,\n",
       "         1.25528372e+00],\n",
       "       [-1.04838982e+00,  3.11391996e-01, -1.45666979e+00,\n",
       "        -1.33929877e+00],\n",
       "       [ 3.49463274e-01, -5.72287992e-01,  5.41229996e-01,\n",
       "         7.36367223e-01],\n",
       "       [ 4.13847651e-15, -1.30447998e-01,  7.07721645e-01,\n",
       "         7.36367223e-01],\n",
       "       [-5.82438790e-01,  1.41599198e+00, -1.29017814e+00,\n",
       "        -1.33929877e+00],\n",
       "       [ 5.82438790e-01,  3.11391996e-01,  8.18716077e-01,\n",
       "         1.38501285e+00],\n",
       "       [-5.82438790e-01,  7.53231990e-01, -1.29017814e+00,\n",
       "        -1.07984052e+00],\n",
       "       [ 2.32975516e-01, -3.51367995e-01,  4.85732779e-01,\n",
       "         2.17450723e-01],\n",
       "       [ 2.32975516e-01, -1.01412799e+00,  9.85207726e-01,\n",
       "         2.17450723e-01],\n",
       "       [ 4.65951032e-01, -1.23504798e+00,  5.96727212e-01,\n",
       "         3.47179848e-01]])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 标准化\n",
    "Xtrain_std =  StandardScaler().fit_transform(Xtrain)\n",
    "Xtrain_std"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "hourly-movement",
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-1.53220047e-01, -1.37279645e-01,  5.45585397e-01,\n",
       "         5.19486735e-01],\n",
       "       [ 1.08786233e+00, -1.37279645e-01,  1.33560386e+00,\n",
       "         1.48206510e+00],\n",
       "       [ 2.60474080e+00, -1.37279645e-01,  1.82176906e+00,\n",
       "         1.34455390e+00],\n",
       "       [-1.39430243e+00,  3.77519023e-01, -1.39907542e+00,\n",
       "        -1.26815879e+00],\n",
       "       [-9.80608300e-01,  8.92317690e-01, -1.27753412e+00,\n",
       "        -1.26815879e+00],\n",
       "       [ 1.22576037e-01, -9.09477646e-01,  3.02502794e-01,\n",
       "        -1.68069238e-01],\n",
       "       [-7.04812216e-01,  1.14971702e+00, -1.27753412e+00,\n",
       "        -1.26815879e+00],\n",
       "       [-2.91118089e-01, -1.16687698e+00,  4.84814746e-01,\n",
       "         1.06953151e-01],\n",
       "       [ 3.98372122e-01, -1.37279645e-01,  7.27897349e-01,\n",
       "         9.32020318e-01],\n",
       "       [ 5.36270164e-01, -1.37279645e-01,  6.06356048e-01,\n",
       "         3.81975540e-01],\n",
       "       [ 1.63945450e+00,  1.20119689e-01,  1.09252125e+00,\n",
       "         1.34455390e+00],\n",
       "       [-4.29016131e-01, -1.37279645e-01,  5.45585397e-01,\n",
       "         5.19486735e-01],\n",
       "       [-1.53220047e+00,  1.40711636e+00, -1.58138738e+00,\n",
       "        -1.26815879e+00],\n",
       "       [-9.80608300e-01, -1.37279645e-01, -1.21676347e+00,\n",
       "        -1.26815879e+00],\n",
       "       [ 1.50155646e+00, -1.37279645e-01,  1.15329190e+00,\n",
       "         1.34455390e+00],\n",
       "       [ 1.22576037e-01, -9.09477646e-01,  1.80961493e-01,\n",
       "         1.06953151e-01],\n",
       "       [-1.80799655e+00,  3.77519023e-01, -1.39907542e+00,\n",
       "        -1.26815879e+00],\n",
       "       [-1.53220047e+00,  8.92317690e-01, -1.33830477e+00,\n",
       "        -1.13064760e+00],\n",
       "       [-1.25640438e+00,  8.92317690e-01, -1.21676347e+00,\n",
       "        -1.26815879e+00],\n",
       "       [-8.42710258e-01,  1.92191502e+00, -1.21676347e+00,\n",
       "        -1.26815879e+00],\n",
       "       [-4.29016131e-01,  8.92317690e-01, -1.15599282e+00,\n",
       "        -1.26815879e+00],\n",
       "       [ 1.36365842e+00, -1.37279645e-01,  9.70979951e-01,\n",
       "         1.61957629e+00],\n",
       "       [-2.91118089e-01, -1.42427631e+00,  2.41732144e-01,\n",
       "         2.44464346e-01],\n",
       "       [-1.25640438e+00, -1.37279645e-01, -1.33830477e+00,\n",
       "        -1.40566999e+00],\n",
       "       [ 1.08786233e+00, -6.52078312e-01,  6.06356048e-01,\n",
       "         5.19486735e-01],\n",
       "       [ 8.12066248e-01,  6.34918356e-01,  6.67126698e-01,\n",
       "         6.56997929e-01],\n",
       "       [-8.42710258e-01,  8.92317690e-01, -1.27753412e+00,\n",
       "        -1.26815879e+00],\n",
       "       [-2.91118089e-01,  2.95151236e+00, -1.33830477e+00,\n",
       "        -1.26815879e+00],\n",
       "       [-2.91118089e-01, -1.68167565e+00,  5.94201917e-02,\n",
       "        -1.68069238e-01],\n",
       "       [ 1.22576037e+00, -3.94678978e-01,  6.06356048e-01,\n",
       "         2.44464346e-01],\n",
       "       [-9.80608300e-01, -1.93907498e+00, -1.83662411e-01,\n",
       "        -1.68069238e-01],\n",
       "       [ 8.12066248e-01, -9.09477646e-01,  7.88667999e-01,\n",
       "         9.32020318e-01],\n",
       "       [ 1.36365842e+00,  6.34918356e-01,  1.27483320e+00,\n",
       "         1.34455390e+00],\n",
       "       [-9.80608300e-01,  6.34918356e-01, -1.33830477e+00,\n",
       "        -1.26815879e+00],\n",
       "       [-8.42710258e-01,  1.14971702e+00, -1.33830477e+00,\n",
       "        -1.13064760e+00],\n",
       "       [ 9.49964291e-01,  3.77519023e-01,  5.45585397e-01,\n",
       "         5.19486735e-01],\n",
       "       [ 8.12066248e-01,  8.92317690e-01,  1.21406255e+00,\n",
       "         1.75708748e+00],\n",
       "       [-1.53220047e-01, -3.94678978e-01, -1.35045890e-03,\n",
       "         2.44464346e-01],\n",
       "       [ 2.60474080e-01,  3.77519023e-01,  7.27897349e-01,\n",
       "         9.32020318e-01],\n",
       "       [-1.53220047e-02, -6.52078312e-01,  5.45585397e-01,\n",
       "         2.44464346e-01],\n",
       "       [-2.91118089e-01, -1.68167565e+00,  1.20190842e-01,\n",
       "        -3.05580432e-02],\n",
       "       [ 6.74168206e-01, -3.94678978e-01,  4.24044096e-01,\n",
       "         2.44464346e-01],\n",
       "       [-2.91118089e-01, -1.93907498e+00,  2.41732144e-01,\n",
       "         2.44464346e-01],\n",
       "       [ 3.98372122e-01, -9.09477646e-01,  9.10209301e-01,\n",
       "         6.56997929e-01],\n",
       "       [ 1.08786233e+00, -1.37279645e-01,  1.15329190e+00,\n",
       "         9.32020318e-01]])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Xtest_std = StandardScaler().fit_transform(Xtest)\n",
    "Xtest_std"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "rural-therapy",
   "metadata": {},
   "source": [
    "# 建模"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "nutritional-strike",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "GridSearchCV(cv=5, estimator=LogisticRegression(max_iter=10000),\n",
       "             param_grid={'C': [0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6,\n",
       "                               0.7000000000000001, 0.8, 0.9, 1.0],\n",
       "                         'solver': ['liblinear', 'sag', 'newton-cg', 'lbfgs']})"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#在l2范式下，使用网格搜索判断solver, C的最优组合\n",
    "p = {'C':list(np.linspace(0.1,1,10)),'solver':['liblinear','sag','newton-cg','lbfgs']}\n",
    "\n",
    "model = LR(penalty='l2',max_iter=10000)\n",
    "\n",
    "GS = GridSearchCV(model,p,cv=5)\n",
    "GS.fit(Xtrain_std,Ytrain)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "center-stream",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'C': 0.4, 'solver': 'sag'}"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "GS.best_params_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "talented-blood",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9714285714285715"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "GS.best_score_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "automotive-response",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LogisticRegression(C=0.4, max_iter=10000, solver='sag')"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "GS.best_estimator_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "lesser-paper",
   "metadata": {},
   "outputs": [],
   "source": [
    "#将最优的结果重新用来实例化模型\n",
    "model = LR(penalty='l2',max_iter=10000,C=GS.best_params_['C'],\n",
    "          solver=GS.best_params_['solver'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "mature-electric",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9809523809523809"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#训练集分数\n",
    "model.fit(Xtrain_std,Ytrain)\n",
    "model.score(Xtrain_std,Ytrain)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "sixth-bidding",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9555555555555556"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#测试集分数\n",
    "model.fit(Xtest_std,Ytest)\n",
    "model.score(Xtest_std,Ytest)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "modular-perspective",
   "metadata": {},
   "source": [
    "# 计算精准度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "rotary-public",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 2, 0, 0, 1, 0, 1, 1, 1, 2, 1, 0, 0, 2, 1, 0, 0, 0, 0, 0, 2,\n",
       "       1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 2, 0, 0, 1, 2, 1, 1, 1, 1, 1, 1, 1,\n",
       "       2])"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Ytest_prep = model.predict(Xtest_std)\n",
    "\n",
    "Ytest_prep\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "functioning-asthma",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9555555555555556"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#F-score\n",
    "metrics.f1_score(Ytest,Ytest_prep,average='micro')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "allied-friend",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[15,  0,  0],\n",
       "       [ 0, 20,  0],\n",
       "       [ 0,  2,  8]], dtype=int64)"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#混淆矩阵\n",
    "metrics.confusion_matrix(Ytest,Ytest_prep)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "bearing-specific",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9555555555555556"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#准确率\n",
    "metrics.accuracy_score(Ytest,Ytest_prep)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "documentary-collective",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9555555555555556"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#精确率\n",
    "metrics.precision_score(Ytest,Ytest_prep,average='micro')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "patent-montreal",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9555555555555556"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#召回率\n",
    "metrics.recall_score(Ytest,Ytest_prep,average='micro')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "aware-sweden",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.2"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
